package com.ddyx.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ddyx.entity.Customer;
import com.ddyx.entity.WxUser;
import com.ddyx.mapper.CustomerMapper;
import com.ddyx.mapper.WxUserMapper;
import com.ddyx.service.ICustomerService;
import com.ddyx.util.MyBeanUtils;
import com.ddyx.util.PageUtil;
import com.ddyx.util.RequestForm;
import com.ddyx.util.ResponseForm;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

@Service
@Slf4j
public class CustomerServiceImpl implements ICustomerService {

	@Resource
	CustomerMapper customerMapper;
	
	@Resource
	WxUserMapper wxUserMapper;

	/*
	 * 获取门店全部客户
	 */
	@SuppressWarnings("unchecked")
	@Override
	public ResponseForm getAllCustomer(RequestForm param) {
		ResponseForm result = new ResponseForm();
		if(param.getData()!=null) {
			Map<String, Object> paramMap = (Map<String, Object>) param.getData();
			
			try {
				paramMap = com.ddyx.util.Page.parsePage(paramMap);
				Page<Object> pageHelper = PageHelper.startPage((int) paramMap.get("page"), (int) paramMap.get("size"));
				List<WxUser> list = customerMapper.getAllCustomer(paramMap);
				
				result.setData(list);
				result.setTotal((int) pageHelper.getTotal());
			} catch (Exception e) {
				e.printStackTrace();
				result.setStatus(false);
				result.setMessage("操作有误");
				log.error("操作有误");
			}
			return result;
		}
		return null;
	}
	
	/*
	 * 获取门店全部客户
	 */
	@Override
	public ResponseForm getAllCustomerCount(RequestForm param) {
		ResponseForm result = new ResponseForm();
		if(param.getData()!=null) {
			Customer customer = new Customer();
			Map<String, Object> paramMap = (Map<String, Object>) param.getData();
			try {
				customer.setStoreNo(paramMap.get("storeNo")+"");
				int customerCount = customerMapper.selectCount(customer);
				result.setData(customerCount);
			} catch (Exception e) {
				e.printStackTrace();
				result.setStatus(false);
				result.setMessage("操作有误");
				log.error("操作有误");
			}
			return result;
		}
		return null;		
	}

}
